package com.huicharge.huichargecrm.dao.impl;

import com.huicharge.huichargecrm.converter.AutoMobileSalesServiceShopConverter;
import com.huicharge.huichargecrm.exception.BusinessException;
import com.huicharge.huichargecrm.model.dto.ShopInsertDTO;
import com.huicharge.huichargecrm.model.dto.ShopModifyDTO;
import com.huicharge.huichargecrm.model.entity.AutomobileSalesServiceShopDO;
import com.huicharge.huichargecrm.mapper.AutomobileSalesServiceShopMapper;
import com.huicharge.huichargecrm.result.ResultCodes;
import com.huicharge.huichargecrm.dao.IAutomobileSalesServiceShopDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 4s店铺 服务实现类
 * </p>
 *
 * @author 小牛
 * @since 2024-12-17
 */
@Service
public class AutomobileSalesServiceShopDaoImpl extends ServiceImpl<AutomobileSalesServiceShopMapper, AutomobileSalesServiceShopDO> implements IAutomobileSalesServiceShopDao {
    @Resource
    private AutoMobileSalesServiceShopConverter shopConverter;
    /*
     *新增4s店
     * */
    @Override
    public Boolean addAutomobileSalesServiceShop(ShopInsertDTO dto) {
        AutomobileSalesServiceShopDO shop =
        shopConverter.toDO(dto);
        return this.save(shop);
    }

    /*
     *修改4S店
     * */
    @Override
    public Boolean modifyAutomobileSalesServiceShop(ShopModifyDTO dto) {
        AutomobileSalesServiceShopDO shop = this.lambdaQuery()
                .eq(AutomobileSalesServiceShopDO::getId, dto.getId())
                .one();
        if (shop == null) {
            throw new BusinessException(ResultCodes.OPERATION_EXCEPTION);//没有该店铺
        }
        shop = shopConverter.toDO(dto);
        return this.updateById(shop);
    }

    /*
     *软删除4S店
     * */
    @Override
    public Boolean deleteAutomobileSalesServiceShop(Integer id) {
        return this.lambdaUpdate()
                .set(id!=null, AutomobileSalesServiceShopDO::getDeleted, true)
                .eq(AutomobileSalesServiceShopDO::getId, id)
                .update();
    }
}
